package com.ken.blog.configure;

import com.ken.blog.filter.WebFilter;
import com.ken.blog.filter.WordFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * web mvc配置类
 */
@Configuration
public class WebMvcConfigure extends WebMvcConfigurerAdapter {

    @Autowired
    private WordFilter wordFilter;

    @Autowired
    private WebFilter webFilter;

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/login").setViewName("login");
    }

    /**
     * 添加过滤器（拦截器）
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(wordFilter).addPathPatterns("/admin/**");
        registry.addInterceptor(webFilter).addPathPatterns("/**");
    }
}